#include <iostream>
#include "Thread.hpp"
#include "ThreadPool.hpp"
#include "Log.hpp"
#include <unistd.h>
#include <vector>
#include <time.h>
#include <sys/types.h>

using namespace ThreadMoudle;
using namespace LogMoudule;
using namespace ThreadPoolMoudule;


using task_t = std::function<void()>;

const int N = 20;



void test1()
{
    int cnt = 5;
    while (true)
    {
        std::cerr << "Ciallo～(∠・ω ∠)⌒☆"<<std::endl;
        sleep(2);
    }
}

void test2()
{
    int cnt = 5;
    while (true)
    {
        LOG(LogLevel::DEBUG) << "Ciallo～泥嚎⌒☆";
        sleep(2);
    }
}

void log()
{
    sleep(3);
    LOG(LogLevel::DEBUG)<<"日志已保存";
}


int main()
{
    ENABLE_CONSOLE_LOG();
    // ENABLE_FILE_LOG();


    task_t arr[] = {test1,test2,log};


    srand(time(0));

    // thread_pool.InitThreadPool();
    // LOG(LogLevel::DEBUG)<<"InitThreadPool()";
    // ThreadPool<task_t>::getInstance()->Start();



    int n = 20;
    while(n--)
    {
        ThreadPool<task_t>::getInstance()->Enqueue(test1);
        // LOG(LogLevel::DEBUG)<<"一个任务进入线程池，还剩任务："<<n;
        // sleep(3);
    }

    // ThreadPool<task_t>::getInstance()->Stop();
    ThreadPool<task_t>::getInstance()->Wait();

    LOG(LogLevel::DEBUG)<<"线程池已停止";




    return 0;
}
